package main

import (
	"ginjwt/config"
	"ginjwt/controllers"
	"ginjwt/middlewares"

	"github.com/gin-gonic/gin"
)

// 路由配置
func setupRouter() *gin.Engine {
	router := gin.Default()
	// 如果HTTP方法路由不支持，应该返回405而不是404
	router.HandleMethodNotAllowed = true

	v1 := router.Group("/api/v1")
	{
		v1.GET("/", controllers.Home)
		v1.POST("/jwt/create/", controllers.JWTCreate)
		v1.POST("/jwt/refresh/", controllers.JWTRefresh)
		v1.GET("/protected/", middlewares.AuthMiddleware(), controllers.Protected)
	}

	return router
}

func main() {
	router := setupRouter()

	// 配置文件初始化
	config.Init("dev")
	conf := config.GetConfig()

	router.Run(":" + conf.GetString("SERVER.PORT"))
}
